home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / WordSet.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-05-25  |  653 b   |  26 lines

  1. //: C20:WordSet.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. #include "../require.h"
  7. #include <string>
  8. #include <fstream>
  9. #include <iostream>
  10. #include <set>
  11. using namespace std;
  12.  
  13. int main(int argc, char* argv[]) {
  14.   requireArgs(argc, 1);
  15.   ifstream source(argv[1]);
  16.   assure(source, argv[1]);
  17.   string word;
  18.   set<string> words;
  19.   while(source >> word)
  20.     words.insert(word);
  21.   copy(words.begin(), words.end(),
  22.     ostream_iterator<string>(cout, "\n"));
  23.   cout << "Number of unique words:" 
  24.     << words.size() << endl;
  25. } ///:~
  26.